#include "accesstoken_kit.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"


extern "C" {
#include "plugin.h"
void AddPermission()
    {
        uint64_t tokenId;
        const char *perms[1];
        perms[0] = "ohos.permission.READ_DFX_SYSEVENT";
        NativeTokenInfoParams infoInstance = {
                .dcapsNum = 0,
                .permsNum = 1,
                .aclsNum = 0,
                .dcaps = NULL,
                .perms = perms,
                .acls = NULL,
                .processName = "collectd",
                .aplStr = "normal",
        };
        
        tokenId = GetAccessTokenId(&infoInstance);
        if (tokenId == 0) {
            ERROR("AddPermission: GetAccessTokenId failed");
            return ;
        }
        
        int ret = SetSelfTokenID(tokenId);
        if (ret != 0) {
            ERROR("AddPermission: SetSelfTokenID failed, ret = %d", ret);
            return;
        }
        
        int reloadRet = OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
        if (reloadRet != 0) {
            ERROR("AddPermission: ReloadNativeTokenInfo failed, ret = %d", reloadRet);
            return ;
        }
    }
}
